<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>新增信息</title>
  <link rel="stylesheet" href="mobile/layui/css/layui.mobile.css">
  <link rel="stylesheet" href="mobile/layui/css/layui.css">
  <link rel="stylesheet" href="mobile/css/yj_css.css">
</head>
<body>
  <header class="yj-header">
    <a href="javascript:history.go(-1)" class="yj-header-return layui-icon">&#xe603;</a>
    <span>上传信息</span>
    <a class="yj-header-meau"></a>
  </header>
  <div class="yj-content">
    <div class="layui-upload">
      <button type="button" class="layui-btn layui-btn-normal"  id="test1">行驶证上传</button>
      <button type="button" class="layui-btn" id="test2">开始上传</button>
      <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
        预览图：
        <div class="layui-upload-list" id="demo2"></div>
      </blockquote>
    </div>
  </div>
  <script src="mobile/js/jquery.min.js"></script>
  <script src="mobile/layui/layui.js"></script>
  <script>
    layui.use('upload', function(){
      var $ = layui.jquery
              ,upload = layui.upload;


      //多图片上传
      upload.render({
        elem: '#test1'
        ,url: 'drivingPermit'
        ,auto: false
        ,choose: function(obj){
          //预读本地文件示例，不支持ie8
          obj.preview(function(index, file, result){
            $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img" style="\n' +
                    '    width: 156px;\n' +
                    '    height: 100px;\n' +
                    '">')
          });
        }
        ,bindAction: '#test2'
        ,done: function(res){
          //上传完毕
          if (res.code == 200) {
            setTimeout(function () {
              window.location.href = "user/authentication";
            }, 2000);
            return layer.msg('上传成功',{icon:6});
          }
          if (res.code == 500) {
            setTimeout(function () {
              window.location.reload();
            }, 1500);
            return layer.msg(res.msg,{icon:5});
          }
        }
      });



    });
  </script>
</body>
</html>